# 绘制炮弹
import pygame


# 普通子弹类
class Bullet(pygame.sprite.Sprite):
    def __init__(self) -> None:
        super().__init__()
        # 子弹图片显示
        self.image = pygame.image.load(r'img/bullet/blue_bullet.png').convert_alpha()
        self.rect = self.image.get_rect()
        # 默认子弹不出现
        self.active = False
        self.speed = 5
        # 标志位，判断碰撞使用
        self.mask = pygame.mask.from_surface(self.image)
        # 是否为超级子弹
        self.is_super = False

    def move_up(self):
        self.rect.top -= self.speed
        if self.rect.top + self.rect.height < 0:
            self.active = False

    def reset(self, gun):
        """ 根据我方大炮，重新设置变量值 """
        self.active = True
        self.rect.left = gun.img_rect.left + (gun.img_rect.width / 2) - (self.rect.width / 2)
        self.rect.top = gun.img_rect.top - self.rect.height + 5

    def update(self):
        """ 更新参数 """
        self.move_up()  # 移动子弹

    def collision(self, fishes: pygame.sprite.Group) -> bool:
        """ 判断子弹是否碰到鱼 """
        is_net = pygame.sprite.spritecollide(self, fishes, False, pygame.sprite.collide_mask)
        if is_net:
            self.active = False
            return True
        else:
            return False


class SuperBullet(Bullet):
    def __init__(self):
        super().__init__()
        self.image = pygame.image.load(r'img/bullet/purple_bullet.png').convert_alpha()
        self.speed = 7
        # 标志位，判断碰撞使用
        self.mask = pygame.mask.from_surface(self.image)
        self.is_super = True
